<?php
/**
 * +----------------------------------------------------------------------
 * | Copyright © Sogu Technologies Co. Ltd 2018-2050 All rights reserved.
 * +----------------------------------------------------------------------
 * | File name: Sign.php
 * +----------------------------------------------------------------------
 * | Author: sam
 * +----------------------------------------------------------------------
 * | Description: RSA签名方法
 * +----------------------------------------------------------------------
 * | Others: 其他内容的说明
 * +----------------------------------------------------------------------
 * | History: 修改历史记录列表，每条修改记录应包含修改日期、修改者及修改内容简述
 * +----------------------------------------------------------------------
 * | 1.Date: 2018/12/26 Author: sam Modification: 创建
 * +----------------------------------------------------------------------
 */

namespace App\Library\Upload;


use App\Exceptions\GeneralException;
use App\Facades\SamLogFacade;
use App\Library\ArrayTools\ArrayTools;
use GuzzleHttp\Client;
use League\Flysystem\Filesystem;
use League\Flysystem\Sftp\SftpAdapter;

class UploadIdCard
{
    /**
     * Description:获取图片信息
     * Author: Sam
     * DateTime: 2019/1/9 11:05
     * @param $url
     * @param string $method
     * @return string
     * @throws GeneralException
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public static function getImageInfo($url,$method="get"){
        $client = new Client(['base_uri'=>$url,'timeout'=>30.0]);
        try{
            $ret = $client->request($method,$url,['content-type'=>'image/jpeg','verify'=>false]);
        }catch (\Exception $e){
            SamLogFacade::debug('获取图片信息失败:'.$e->getMessage().'url:'.$url);
            throw new GeneralException($e->getMessage());
        }
        return $ret->getBody()->getContents();
    }

    /**
     * Description:上传图片
     * Author: Sam
     * DateTime: 2019/1/9 11:05
     * @param $name
     * @param $img
     * @return bool
     */
    public static function imageUpload($name,$img)
    {
        $config = config('flysystem.connections.sftp');
        $filesystem = new Filesystem(new SftpAdapter($config));
        $return = $filesystem->put($name,$img);
        return $return;
    }


}